package scau.zhong.pojo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import scau.zhong.common.genid.UUIdGenId;
import tk.mybatis.mapper.annotation.KeySql;

import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.Collection;
import java.util.List;

@Data
@Table(name = "users")
public class User implements UserDetails {

    @Id
    @KeySql(genId = UUIdGenId.class)
    private String id;
    private String username;
    private String email;
    private String password;
    private String phoneNum;
    private Integer status;
    @Transient
    private String statusStr = "";
    @Transient
    private List<Role> roles;

    public String getStatusStr() {
        if(status==1){
            statusStr = "开启";
        }else {
            statusStr = "未开启";
        }
        return statusStr;
    }



    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return this.roles;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return this.status == 1;
    }
}
